from sqlalchemy import Integer, String, ForeignKey
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column, relationship

from app.models.base import Base


class Users(Base):
    __tablename__ = "users"
    name: Mapped[str] = mapped_column(String(30), unique=True)
    amount: Mapped[int] = mapped_column(Integer)
    tgbot: Mapped["TgBot"] = relationship("TgBot", back_populates="user")

    def add(self, n):
        self.amount += n


class TgBot(Base):
    __tablename__ = "tgbot"
    name: Mapped[str] = mapped_column(ForeignKey("users.name"), unique=True)
    user: Mapped["Users"] = relationship("Users", back_populates="tgbot", lazy="joined")
